

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>RBD Persistent Write-back Cache &mdash; Ceph Documentation</title>
  

  
  <link rel="stylesheet" href="../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/graphviz.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" />

  
  
    <link rel="shortcut icon" href="../../_static/favicon.ico"/>
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/doctools.js"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../genindex/" />
    <link rel="search" title="Search" href="../../search/" />
    <link rel="next" title="Image Encryption" href="../rbd-encryption/" />
    <link rel="prev" title="RBD 永久只读缓存" href="../rbd-persistent-read-only-cache/" /> 
</head>

<body class="wy-body-for-nav">

   
  <header class="top-bar">
    

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../" class="icon icon-home"></a> &raquo;</li>
        
          <li><a href="../">Ceph 块设备</a> &raquo;</li>
        
          <li><a href="../rbd-operations/">Ceph 块设备运维</a> &raquo;</li>
        
      <li>RBD Persistent Write-back Cache</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="../../_sources/rbd/rbd-persistent-write-back-cache.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
  </header>
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search"  style="background: #eee" >
          

          
            <a href="../../">
          

          
            
            <img src="../../_static/logo.png" class="logo" alt="Logo"/>
          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search/" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../start/intro/">Ceph 简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../install/">安装 Ceph</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../cephadm/">Cephadm</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../rados/">Ceph 存储集群</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../cephfs/">Ceph 文件系统</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../">Ceph 块设备</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../rados-rbd-cmds/">基本命令</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../rbd-operations/">运维</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="../rbd-snapshot/">快照</a></li>
<li class="toctree-l3"><a class="reference internal" href="../rbd-exclusive-locks/">互斥锁</a></li>
<li class="toctree-l3"><a class="reference internal" href="../rbd-mirroring/">镜像</a></li>
<li class="toctree-l3"><a class="reference internal" href="../rbd-live-migration/">实时迁移</a></li>
<li class="toctree-l3"><a class="reference internal" href="../rbd-persistent-read-only-cache/">永久只读缓存</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">永久回写缓存</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#persistent-write-back-cache">Persistent Write-back Cache</a></li>
<li class="toctree-l4"><a class="reference internal" href="#usage">Usage</a></li>
<li class="toctree-l4"><a class="reference internal" href="#enable-persistent-write-back-cache">Enable Persistent Write-back Cache</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../rbd-encryption/">加密</a></li>
<li class="toctree-l3"><a class="reference internal" href="../rbd-config-ref/">配置选项 (librbd)</a></li>
<li class="toctree-l3"><a class="reference internal" href="../rbd-replay/">RBD 重放</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../rbd-integrations/">对接</a></li>
<li class="toctree-l2"><a class="reference internal" href="../man/">手册页</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/">APIs</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../radosgw/">Ceph 对象网关</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mgr/">Ceph 管理器守护进程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mgr/dashboard/">Ceph 仪表盘</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/">API 文档</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../architecture/">体系结构</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev/developer_guide/">开发者指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev/internals/">Ceph 内幕</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../governance/">项目管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../foundation/">Ceph 基金会</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../ceph-volume/">ceph-volume</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../releases/general/">Ceph 版本（总目录）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../releases/">Ceph 版本（索引）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../security/">Security</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../glossary/">Ceph 术语</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../jaegertracing/">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../translation_cn/">中文版翻译资源</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../">Ceph</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
<div id="dev-warning" class="admonition note">
  <p class="first admonition-title">Notice</p>
  <p class="last">This document is for a development version of Ceph.</p>
</div>
  <div id="docubetter" align="right" style="padding: 5px; font-weight: bold;">
    <a href="https://pad.ceph.com/p/Report_Documentation_Bugs">Report a Documentation Bug</a>
  </div>

  
  <div class="section" id="rbd-persistent-write-back-cache">
<h1>RBD Persistent Write-back Cache<a class="headerlink" href="#rbd-persistent-write-back-cache" title="Permalink to this headline">¶</a></h1>
<div class="section" id="persistent-write-back-cache">
<span id="index-0"></span><h2>Persistent Write-back Cache<a class="headerlink" href="#persistent-write-back-cache" title="Permalink to this headline">¶</a></h2>
<p>The persistent write-back cache provides a persistent, fault-tolerant write-back
cache for librbd-based RBD clients.</p>
<p>This cache uses a log-ordered write-back design which maintains checkpoints
internally so that writes that get flushed back to the cluster are always
crash consistent. Even if the client cache is lost entirely, the disk image is
still consistent but the data will appear to be stale.</p>
<p>This cache can be used with PMEM or SSD as a cache device.</p>
</div>
<div class="section" id="usage">
<h2>Usage<a class="headerlink" href="#usage" title="Permalink to this headline">¶</a></h2>
<p>The persistent write-back cache manages the cache data in a persistent device.
It looks for and creates cache files in a configured directory, and then caches
data in the file.</p>
<p>The persistent write-back cache can’t be enabled without the exclusive-lock
feature. It tries to enable the write-back cache only when the exclusive lock
is acquired.</p>
<p>The cache provides two different persistence modes. In persistent-on-write mode,
the writes are completed only when they are persisted to the cache device and
will be readable after a crash. In persistent-on-flush mode, the writes are
completed as soon as it no longer needs the caller’s data buffer to complete
the writes, but does not guarantee that writes will be readable after a crash.
The data is persisted to the cache device when a flush request is received.</p>
<p>Initially it defaults to the persistent-on-write mode and it switches to
persistent-on-flush mode after the first flush request is received.</p>
</div>
<div class="section" id="enable-persistent-write-back-cache">
<h2>Enable Persistent Write-back Cache<a class="headerlink" href="#enable-persistent-write-back-cache" title="Permalink to this headline">¶</a></h2>
<p>To enable the persistent write-back cache, the following Ceph settings
need to be enabled.:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">rbd</span> <span class="n">persistent</span> <span class="n">cache</span> <span class="n">mode</span> <span class="o">=</span> <span class="p">{</span><span class="n">cache</span><span class="o">-</span><span class="n">mode</span><span class="p">}</span>
<span class="n">rbd</span> <span class="n">plugins</span> <span class="o">=</span> <span class="n">pwl_cache</span>
</pre></div>
</div>
<p>Value of {cache-mode} can be <code class="docutils literal notranslate"><span class="pre">rwl</span></code>, <code class="docutils literal notranslate"><span class="pre">ssd</span></code> or <code class="docutils literal notranslate"><span class="pre">disabled</span></code>. By default the
cache is disabled.</p>
<p>Here are some cache configuration settings:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">rbd_persistent_cache_path</span></code> A file folder to cache data. This folder must
have DAX enabled (see <a class="reference external" href="https://www.kernel.org/doc/Documentation/filesystems/dax.txt">DAX</a>) when using <code class="docutils literal notranslate"><span class="pre">rwl</span></code> mode to avoid performance
degradation.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">rbd_persistent_cache_size</span></code> The cache size per image. The minimum cache
size is 1 GB.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">rbd_persistent_cache_log_periodic_stats</span></code> This is a debug option. It is
used to emit periodic perf stats to the debug log if <code class="docutils literal notranslate"><span class="pre">debug</span> <span class="pre">rbd</span> <span class="pre">pwl</span></code> is
set to <code class="docutils literal notranslate"><span class="pre">1</span></code> or higher.</p></li>
</ul>
<p>The above configurations can be set per-host, per-pool, per-image etc. Eg, to
set per-host, add the overrides to the appropriate <a class="reference external" href="../../rados/configuration/ceph-conf/#configuration-sections">section</a> in the host’s
<code class="docutils literal notranslate"><span class="pre">ceph.conf</span></code> file. To set per-pool, per-image, etc, please refer to the
<code class="docutils literal notranslate"><span class="pre">rbd</span> <span class="pre">config</span></code> <a class="reference external" href="../../man/8/rbd#commands">commands</a>.</p>
<div class="section" id="cache-status">
<h3>Cache Status<a class="headerlink" href="#cache-status" title="Permalink to this headline">¶</a></h3>
<p>The persistent write-back cache is enabled when the exclusive lock is acquired,
and it is closed when the exclusive lock is released. To check the cache status,
users may use the command <code class="docutils literal notranslate"><span class="pre">rbd</span> <span class="pre">status</span></code>.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">rbd</span> <span class="n">status</span> <span class="p">{</span><span class="n">pool</span><span class="o">-</span><span class="n">name</span><span class="p">}</span><span class="o">/</span><span class="p">{</span><span class="n">image</span><span class="o">-</span><span class="n">name</span><span class="p">}</span>
</pre></div>
</div>
<p>The status of the cache is shown, including present, clean, cache size and the
location. Currently the status is updated only at the time the cache is opened
and closed and therefore may appear to be out of date (e.g. show that the cache
is clean when it is actually dirty).</p>
<p>For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ rbd status rbd/foo
Watchers: none
Image cache state: {&quot;present&quot;:&quot;true&quot;,&quot;empty&quot;:&quot;false&quot;,&quot;clean&quot;:&quot;true&quot;,&quot;cache_type&quot;:&quot;ssd&quot;,&quot;pwl_host&quot;:&quot;sceph9&quot;,&quot;pwl_path&quot;:&quot;/tmp/rbd-pwl.rbd.abcdef123456.pool&quot;,&quot;pwl_size&quot;:1073741824}
</pre></div>
</div>
</div>
<div class="section" id="discard-cache">
<h3>Discard Cache<a class="headerlink" href="#discard-cache" title="Permalink to this headline">¶</a></h3>
<p>To discard a cache file with <code class="docutils literal notranslate"><span class="pre">rbd</span></code>, specify the <code class="docutils literal notranslate"><span class="pre">image-cache</span> <span class="pre">invalidate</span></code>
option, the pool name and the image name.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">rbd</span> <span class="n">image</span><span class="o">-</span><span class="n">cache</span> <span class="n">invalidate</span> <span class="p">{</span><span class="n">pool</span><span class="o">-</span><span class="n">name</span><span class="p">}</span><span class="o">/</span><span class="p">{</span><span class="n">image</span><span class="o">-</span><span class="n">name</span><span class="p">}</span>
</pre></div>
</div>
<p>The command removes the cache metadata of the corresponding image, disable
the cache feature and deletes the local cache file if it exists.</p>
<p>For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ rbd image-cache invalidate rbd/foo
</pre></div>
</div>
</div>
</div>
</div>



           </div>
           
          </div>
          <footer>
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
        <a href="../rbd-encryption/" class="btn btn-neutral float-right" title="Image Encryption" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
        <a href="../rbd-persistent-read-only-cache/" class="btn btn-neutral float-left" title="RBD 永久只读缓存" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2016, Ceph authors and contributors. Licensed under Creative Commons Attribution Share Alike 3.0 (CC-BY-SA-3.0).

    </p>
  </div> 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>